package com.orifine.web.validate;

import com.orifine.web.Domain;
import com.orifine.web.Property;
import com.orifine.web.Validator;

public class NumberValueRule {
	public static Validator min(final int minValue){
		return new Validator() {
			@Override
			public boolean execute(Object... values) {
				Integer value = (Integer) values[0];
				return value >= minValue;
			}

			@Override
			public Property property() {
				return new Property(new Domain("validate.number.value.min"), getDomain(), minValue);
			}
		};
	}
	
	public static Validator max(final int maxValue){
		return new Validator() {
			@Override
			public boolean execute(Object... values) {
				Integer value = (Integer) values[0];
				return value <= maxValue;
			}

			@Override
			public Property property() {
				return new Property(new Domain("validate.number.value.max"), getDomain(), maxValue);
			}
		};
	}
	
	public static Validator range(final int minValue, final int maxValue){
		return new Validator() {
			@Override
			public boolean execute(Object... values) {
				Integer value = (Integer) values[0];
				return value >= minValue && value <= maxValue;
			}

			@Override
			public Property property() {
				return new Property(new Domain("validate.number.value.range"), getDomain(), minValue, maxValue);
			}
		};
	}
}
